<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:t="http://myfaces.apache.org/tomahawk">


    <ui:composition template="./WEB-INF/Templates/templateProjeto.xhtml">
        <ui:define name="titulo">consultaEmpreendimento</ui:define>

        <ui:define name="javascript">
            function controlaRadio(){
                var campo1 = document.getElementById("form:codAPF");
                var campo2 = document.getElementById("form:municipio");
                var campo3 = document.getElementById("form:selectSituacao:0");
                var campo4 = document.getElementById("form:selectSituacao:1");
                var campo5 = document.getElementById("form:limpar");
 

                if(document.getElementById("form:radio0").checked){
                    campo1.disabled=false;
                    campo2.disabled=true;
                    campo3.disabled=true
                    campo4.disabled=true
                    campo5.disabled=true
                 }
                 if(document.getElementById("form:radio1").checked){
                    campo1.disabled=true;
                    campo2.disabled=false;
                    campo3.disabled=false;
                    campo4.disabled=false
                    campo5.disabled=false
                 }
            }
            
            function disable(){
                document.getElementById("form:codAPF").disabled=true;
                document.getElementById("form:municipio").disabled=true;
                document.getElementById("form:selectSituacao").disabled=true;
            }
        </ui:define>
        <ui:define name="tituloH1">Consulta de empreendimentos</ui:define>
        <ui:define name="pagLinda">
            <h1>Selecione os filtros para sua pesquisa</h1>
            <h:messages layout="list" style="color: darkred"/>
            <h:form id="form">
                <br/>
                <h:panelGrid columns="2" id="painel">
                        <h:panelGroup>
                            <t:selectOneRadio id="filtro" layout="spread" value="#{managedEmpreendimento.numRadioPesquisa}" onchange="controlaRadio()">
                                    <f:selectItem itemLabel="Por Codigo APF" itemValue="cod" />
                                    <f:selectItem itemLabel="Selecionar filtros" itemValue="filtro"/>
                            </t:selectOneRadio>
                            <t:radio for="filtro" index="0" id="radio0" />
                        </h:panelGroup>
                        <h:inputHidden/>
                    
                        <b>Codigo APF</b>
                        <h:inputText id="codAPF" label="Codigo APF" value="#{managedEmpreendimento.aprEmp.codigoComDigito}">
                            <f:validator validatorId="validatorApf"/>
                        </h:inputText>
                        
                        <br/>
                        <h:inputHidden/>
                        <t:radio for="filtro" index="1" id="radio1"/>
                        <h:inputHidden/>
                        
                        <b>Código do Municipio</b>
                        <h:inputText id="municipio" label="Municipio" value="#{managedEmpreendimento.aprEmp.municipio}">
                            <f:validateLongRange minimum="0"/>
                        </h:inputText>

                        <b>Situação</b>
                        <h:panelGroup>
                            <h:selectOneRadio id="selectSituacao" value="#{managedEmpreendimento.aprEmp.situacao}">
                                    <f:selectItem itemLabel="Ativo" itemValue='1'/>
                                    <f:selectItem itemLabel="Inativo" itemValue='2'/>
                            </h:selectOneRadio>
                            <h:commandButton value="Limpar CheckBoxes" action="#{managedEmpreendimento.limparCheck}" id="limpar"/>
                        </h:panelGroup>
                </h:panelGrid>
                <br/>
                <h:commandButton value="Pesquisar" action="#{managedEmpreendimento.procurar}"/>
                <h:commandButton value="Pesquisar todos empreendimentos" action="#{managedEmpreendimento.procurarTodos()}" onclick="disable()"/>
                <script>
                    controlaRadio();
                </script>
            </h:form>
        </ui:define>

    </ui:composition>

</html>
